package com.example.controller;

import com.example.po.User;
import com.example.service.TestService;
import com.googlecode.aviator.AviatorEvaluator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
public class TestController {

    @Resource
    private TestService testService;

    @RequestMapping("getTime")
    public String getTime() {
        return testService.getTime();
    }

    @RequestMapping("getTest")
    public String getTest() {
        User user = new User();
        user.setAge(30);
        Map<String, Object> map = new HashMap<>();
        map.put("user", user);
        return AviatorEvaluator.getInstance().execute("SpringFunction2() && SpringFunction1()", map).toString();
    }

    @RequestMapping("add")
    public String add() {
        User user = new User();
        user.setId(UUID.randomUUID().toString());
        testService.add(user, UUID.randomUUID().toString());
        return user.getId();
    }


    @RequestMapping("send")
    public String send() {
        User user = new User();
        user.setId(UUID.randomUUID().toString());
        testService.send(user);
        return user.getId();
    }
}
